<?php defined('SYSPATH') or die('No direct script access.');

/**
 * Kotan page controller containing actions of page module.
 * @author bagnz0r
 * @package Kotan
 */

class Controller_Page extends Controller_Kotan {
	
	/**
	 * Default action.
	 * Redirects to the blog.
	 */
	public function action_index()
	{
		Request::current()->redirect('');
	}
	
	/**
	 * View action.
	 * Responsible for viewing pages.
	 */
	public function action_view()
	{
		// Get the param
		if (!$id = $this->get_param('id', true))
			Request::current()->redirect('');
			
		// Get page
		$page = ORM::factory('page', $id);
		
		// Check if we're not empty
		if ($page->id == '')
			throw new HTTP_Exception_404('Not found', array(0));
			
		// FIXME: Hack! A temporary measure!
		$page->content = str_replace('{base}', URL::base(), $page->content);
			
		// Append to the title
		$this->template->title .= ' -> ' . $page->title;
			
		// Output data to the view
		$this->template->content = View::factory('page/view/index')
										->bind('page', $page);
	}
}